try:
    print('try...')
    r = 10 / int('a')
    print('result:', r)
except ValueError as e:
    print('ValueError:', e)
except ZeroDivisionError as e:
    print('ZeroDivisionError:', e)
finally:
    print('finally...')
print('END')

print("===============================================================")

try:
    print('try...')
    r = 10 / int('2')
    print('result:', r)
except ValueError as e:
    print('ValueError:', e)
except ZeroDivisionError as e:
    print('ZeroDivisionError:', e)
else:
    # 无错误发生时，会执行这里else里的语句
    print('no error!')
finally:
    print('finally...')
print('END')


print("===========================记录错误====================================")
import logging

def foo(s):
    return 10 / int(s)

def bar(s):
    return foo(s) * 2

def main():
    try:
        bar('0')
    except Exception as e:
        # 同样是出错，但程序打印完错误信息后会继续执行，并正常退出
        logging.exception(e)

main()
print('END')


print("============================================================================")
import logging
def func():
    10 / 0
    print("aaaaaaa")
    print("aabbbb")
try:
    func()
except ZeroDivisionError as e:
    logging.exception(e) # 打印完错误日志之后，主程序还是会继续向后执行
print("hello world")




print("============================================================================")

# 抛出异常实例
def func2(a):
    if(a==0):
        raise ValueError("参数的值为0")

try:
    func2(0)
except BaseException as e:
    logging.exception(e)
print("hello world")
